﻿<Window x:Class="PlayRandom.Views.TimestampSelector"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:main="clr-namespace:PlayRandom"
        xmlns:conv="clr-namespace:PlayRandom.Converters"
        xmlns:convUtil="clr-namespace:CommonUtilities.Converters;assembly=CommonUtilities"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        Title="Timestamp Selector" WindowStartupLocation="CenterOwner" WindowStyle="ThreeDBorderWindow" ResizeMode="NoResize" 
        ShowInTaskbar="False" SizeToContent="Height" Width="250" SnapsToDevicePixels="True" Topmost="{Binding IsTimestampInputBoxOnTop}" 
        Loaded="Window_Loaded" Closing="Window_Closing" Closed="Window_Closed" PreviewKeyDown="Window_PreviewKeyDown">
    <Window.Resources>
        <conv:FriendlyNameConverter x:Key="FriendlyNameConverter" />
        <convUtil:VisibilityConverter x:Key="VisibilityConverter" />
        <conv:TimestampFormatConverter x:Key="TimestampFormatConverter" />

        <sys:Int32 x:Key="UnigridColumnCount">3</sys:Int32>
    </Window.Resources>

    <Grid Name="MainLayout" Margin="5">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <StackPanel Orientation="Vertical">
            <TextBlock Name="txtbFileName" Margin="0,0,25,0" FontWeight="Bold" TextWrapping="Wrap" Text="{Binding SelectedFavFile.FileName}" ToolTip="{Binding SelectedFavFile.FilePath}" />
            <TextBlock Name="txtbMediaPlayer" ToolTip="{Binding TimestampMediaPlayer}" 
                       Text="{Binding AppSettings.PlaySettings.MediaPlayer, StringFormat='Play in {0}', Converter={StaticResource FriendlyNameConverter}, ConverterParameter={x:Type main:eMediaPlayer}}" />
        </StackPanel>
        <StackPanel Margin="0,1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Orientation="Horizontal">
            <CheckBox Name="chkSortTimestamp" Margin="1,0" VerticalAlignment="Bottom" VerticalContentAlignment="Bottom" 
                      IsChecked="{Binding IsSortAsc, Mode=TwoWay}" IsThreeState="True" 
                      Checked="chkSortTimestamp_Checked" Unchecked="chkSortTimestamp_Checked" Indeterminate="chkSortTimestamp_Checked" />
            <Button Name="btnAddTimestamp" Height="Auto" Width="{Binding ElementName=btnAddTimestamp, Path=ActualHeight}" 
                    IsEnabled="{Binding IsUpdateMode}" Content="+" Command="{Binding AddTimestampCommand}" CommandParameter="{Binding }" />
        </StackPanel>
        <ListBox Name="lstTimestamp" Grid.Row="1" Padding="3,1" MinHeight="28" ItemsSource="{Binding SelectedFavFile.Timestamps}" SelectionChanged="lstTimestamp_SelectionChanged">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <UniformGrid Columns="{StaticResource UnigridColumnCount}" />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Margin="3,0.5" Orientation="Horizontal">
                        <Button Name="btnPlayAtTimestamp" Padding="3,0.5" 
                                Command="{Binding DataContext.TimestampMouseDoubleClickCommand, RelativeSource={RelativeSource AncestorType=ListBox}}" CommandParameter="{Binding }">
                            <Button.Template>
                                <ControlTemplate TargetType="Button">
                                    <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="5,0,5,0">
                                        <ContentPresenter Margin="{TemplateBinding Padding}" />
                                    </Border>
                                </ControlTemplate>
                            </Button.Template>
                            <StackPanel Margin="3,0" Orientation="Horizontal">
                                <TextBlock Visibility="{Binding DataContext.IsUpdateMode, RelativeSource={RelativeSource AncestorType=ListBox}, Converter={StaticResource VisibilityConverter}, ConverterParameter=-}" Text="Play @ " />
                                <TextBlock Visibility="{Binding DataContext.IsUpdateMode, RelativeSource={RelativeSource AncestorType=ListBox}, Converter={StaticResource VisibilityConverter}}" Text="Update " />
                                <TextBlock FontWeight="Bold" Text="{Binding FallbackValue='00:00', Converter={StaticResource TimestampFormatConverter}}" />
                            </StackPanel>
                        </Button>
                        <Button Name="btnDeleteTimestamp" Margin="-4,0" Padding="4,0" FontWeight="Bold" Foreground="Red" Background="Bisque" Content="x" 
                                Visibility="{Binding DataContext.IsUpdateMode, RelativeSource={RelativeSource AncestorType=ListBox}, Converter={StaticResource VisibilityConverter}}"
                                Command="{Binding DataContext.DeleteTimestampCommand, RelativeSource={RelativeSource AncestorType=ListBox}}" CommandParameter="{Binding }">
                            <Button.Template>
                                <ControlTemplate TargetType="Button">
                                    <Border BorderBrush="Red" Background="{TemplateBinding Background}" BorderThickness="0,0.5,0.5,0.5" CornerRadius="0,0,5,0">
                                        <ContentPresenter Margin="{TemplateBinding Padding}" />
                                    </Border>
                                </ControlTemplate>
                            </Button.Template>
                        </Button>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <StackPanel Grid.Row="2" Margin="0,1" HorizontalAlignment="Right" Orientation="Horizontal">
            <CheckBox Name="chkSaveClose" VerticalAlignment="Center" Content="Close on save?" IsEnabled="{Binding IsDirty}" 
                      Visibility="{Binding IsUpdateMode, Converter={StaticResource VisibilityConverter}}" 
                      IsChecked="{Binding AppSettings.FavouritesSettings.SaveClose, Mode=TwoWay}" />
            <Button Name="btnSaveTimestamp" Margin="3,0" Padding="3,0" Content="Save" IsEnabled="{Binding IsDirty}" 
                    Visibility="{Binding IsUpdateMode, Converter={StaticResource VisibilityConverter}}" Command="{Binding SaveTimestampCommand}" />
            <Button Name="btnCloseTimestamp" Padding="3,0" Content="Close" Command="{Binding CloseTimestampWindowCommand}" />
        </StackPanel>
    </Grid>
</Window>
